//
//  CKeepConnection.m
//  Invest
//
//  Created by 邓晓羽 on 15/1/14.
//  Copyright (c) 2015年 chenliang. All rights reserved.
//

#import "CKeepConnection.h"

@implementation CKeepConnection

#pragma mark - 定时器方式
-(void)startConnect
{
    m_timerForConnect = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL target:self selector:@selector(onTimerToConnect) userInfo:nil repeats:YES];
    m_count = CONNECT_INTERVAL;   //60*60*20
}

-(void) onTimerToConnect {
    NSLog(@"countForConnect: %ld",m_count);
    if (m_count <=0) {
        //和服务器通信
        m_count = CONNECT_INTERVAL;
        [self connect];
    }
    else
    {
        m_count-=TIMER_INTERVAL;
    }
}

-(void)connect
{
    if( [UserDefaultsUtil boolForKey:GLOBALDATA_ISLOGINED] )
    {
        [self sendASI:[BaseURL stringByAppendingString:@"keepConnecting.htm"]  params:nil
              success:^(NSDictionary *dic)
         {
             DLog(@"sucess message:%@",[dic objectForKey:@"message"]);
         }
              failure:^(NSError *error)
         {
             DLog(@"error %@",error);
         }];
    }
}

#pragma mark - 线程方式
@end
